import {useRoute} from "vue-router";

export function onActivatedFunctions(getListFunction, uniqueId) {
    const route = useRoute()

    onActivated(() => {
        const time = route.query.t
        if (time != null && time !== uniqueId.value) {
            uniqueId.value = time
            getListFunction()
        }
    })
}

export function tableFunctions(queryParams, getTableListFunction) {
    function tableSort(item) {
        let orderBy = ''
        switch (item.order) {
            case 'ascending': {
                orderBy = 'asc'
                break
            }
            case 'descending': {
                orderBy = 'desc'
                break
            }
        }
        queryParams.value.orderField = item.prop
        queryParams.value.orderRule = orderBy
        queryParams.value.pageNum = 1
        getTableListFunction()
    }

    return {
        tableSort
    }
}
